package com.ruoyi.costumeShop.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.costumeShop.domain.CostumeCategory;
import com.ruoyi.costumeShop.service.ICostumeCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * categoryController
 * 
 * @author ruoyi
 * @date 2022-03-18
 */
@RestController
@RequestMapping("/costumeShop/category")
public class CostumeCategoryController extends BaseController
{
    @Autowired
    private ICostumeCategoryService costumeCategoryService;

    /**
     * 查询category列表
     */
    @PreAuthorize("@ss.hasPermi('costumeShop:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(CostumeCategory costumeCategory)
    {
        startPage();
        List<CostumeCategory> list = costumeCategoryService.selectCostumeCategoryList(costumeCategory);
        return getDataTable(list);
    }

    /**
     * 导出category列表
     */
    @PreAuthorize("@ss.hasPermi('costumeShop:category:export')")
    @Log(title = "category", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CostumeCategory costumeCategory)
    {
        List<CostumeCategory> list = costumeCategoryService.selectCostumeCategoryList(costumeCategory);
        ExcelUtil<CostumeCategory> util = new ExcelUtil<CostumeCategory>(CostumeCategory.class);
        util.exportExcel(response, list, "category数据");
    }

    /**
     * 获取category详细信息
     */
    @PreAuthorize("@ss.hasPermi('costumeShop:category:query')")
    @GetMapping(value = "/{costumeCategoryId}")
    public AjaxResult getInfo(@PathVariable("costumeCategoryId") Long costumeCategoryId)
    {
        return AjaxResult.success(costumeCategoryService.selectCostumeCategoryByCostumeCategoryId(costumeCategoryId));
    }

    /**
     * 新增category
     */
    @PreAuthorize("@ss.hasPermi('costumeShop:category:add')")
    @Log(title = "category", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CostumeCategory costumeCategory)
    {
        return toAjax(costumeCategoryService.insertCostumeCategory(costumeCategory));
    }

    /**
     * 修改category
     */
    @PreAuthorize("@ss.hasPermi('costumeShop:category:edit')")
    @Log(title = "category", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CostumeCategory costumeCategory)
    {
        return toAjax(costumeCategoryService.updateCostumeCategory(costumeCategory));
    }

    /**
     * 删除category
     */
    @PreAuthorize("@ss.hasPermi('costumeShop:category:remove')")
    @Log(title = "category", businessType = BusinessType.DELETE)
	@DeleteMapping("/{costumeCategoryIds}")
    public AjaxResult remove(@PathVariable Long[] costumeCategoryIds)
    {
        return toAjax(costumeCategoryService.deleteCostumeCategoryByCostumeCategoryIds(costumeCategoryIds));
    }
}
